<%@page import="java.util.Date"%>
<%@page import="com.smfx.yxt.utils.DateUtil"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path;
	String currDate = DateUtil.dateToStr(new Date(), DateUtil.DEFAULT_DATE_FORMAT3);
	String lastDate = DateUtil.getLastDate(1);
%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
<title>学生报名列表-云校通</title>
<jsp:include page="/WEB-INF/page/common/_header.jsp"></jsp:include>
<script src="<%=basePath %>/js/picker.js"></script>

<body ontouchstart style="background-color: #f8f8f8;">

	<div class="weui_tab tab-bottom">
		<div class="page-bd">
	      <ul>
	        <li class="">
	            <div class="weui-flex js-category">
	                <p class="weui-flex-item center" style="text-align: center;">快速查询</p>
	                <i class="icon icon-74"></i>
	            </div>
	            <div class="page-category js-categoryInner">
	              <div class="weui_cells weui_cells_access" style="margin-top: 0px;">
	                <a class="weui_cell" href="javascript:;">
	                  	<div class="weui_cell_bd weui_cell_primary">
	                      <input class="weui_input" type="text" value="<%=lastDate %>" id='startDate'/>
	                    </div>
	                    <div class="weui_cell_bd mr20">到</div>
	                    <div class="weui_cell_bd weui_cell_primary">
	                      <input class="weui_input right" type="text" value="<%=currDate %>" id='endDate'/>    
	                    </div>
	                    <div class="weui_cell_bd" id="search" style="text-align: right; padding: 2px 10px;background: #efefef; border-radius: 5px; color: #18b4ed;">
	                    	查询
	                    </div>
	                </a>   
	              </div>
	            </div>
	        </li>
	      </ul>
	    </div>
		<div class="weui_tab_bd" style="margin-top: -8px;">
			<div class="weui_tab kcfd-list1" id="tab4">
				<div class="weui_navbar">
					<div class="weui_navbar_item" id="newStudentTab">新生</div>
					<div class="weui_navbar_item" id="middleStudentTab">插班生</div>
					<div class="weui_navbar_item" id="internatStudentTab">国际班</div>
				</div>
				<div class="weui_tab_bd">
					<div class="weui_panel weui_tab_bd_item qingjia mt0">
						<div class="weui_panel_bd">
							<div class="weui_media_box weui_media_small_appmsg">
					            <div class="weui_cells weui_cells_access" id="newStudent">
					             	
					            </div>
					            <div class="dropload-down">
								    <div class="loadData dropload-hasData">点击加载更多数据...</div>
								</div>
				            </div>
						</div>
					</div>
					
					<div class="weui_panel weui_tab_bd_item qingjia mt0">
						<div class="weui_panel_bd">
							<div class="weui_media_box weui_media_small_appmsg">
					            <div class="weui_cells weui_cells_access" id="middleStudent">
					             	
					            </div>
					            <div class="dropload-down">
								    <div class="loadData dropload-hasData">点击加载更多数据...</div>
								</div>
				            </div>
						</div>
					</div>
					
					<div class="weui_panel weui_tab_bd_item qingjia mt0">
						<div class="weui_panel_bd">
							<div class="weui_media_box weui_media_small_appmsg">
					            <div class="weui_cells weui_cells_access" id="internatStudent">
					             	
					            </div>
					            <div class="dropload-down">
								    <div class="loadData dropload-hasData">点击加载更多数据...</div>
								</div>
				            </div>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
</body>
<jsp:include page="/WEB-INF/page/common/_footer.jsp"></jsp:include>
<script>
	var xsPage = 1, cbPage = 1, gjPage = 1;
	var isLoadNewStudent = false, isLoadMiddleStudent = false, isLoadInternatStudent = false;
	$(function() {
		$('#tab4').tab({
			defaultIndex : 0,
			activeClass : "tab-blue "
		});
		$("#startDate").datetimePicker({
			title : "选择日期",
			m : 1
		});
		$("#endDate").datetimePicker({
			title : "选择日期",
			m : 1
		});
		$('.js-category').click(function() {
			$parent = $(this).parent('li');
			if ($parent.hasClass('js-show')) {
				$parent.removeClass('js-show');
				$(this).children('i').removeClass('icon-35')
						.addClass('icon-74');
			} else {
				$parent.siblings().removeClass('js-show');
				$parent.addClass('js-show');
				$(this).children('i').removeClass('icon-74')
						.addClass('icon-35');
				$parent.siblings().find('i').removeClass('icon-35')
						.addClass('icon-74');
			}
		});
		$("#search").click(function() {
			var id = $("#tab4 .tab-blue").attr("id");
			$("#newStudent").html("");
			$("#middleStudent").html("");
			$("#internatStudent").html("");
			$('.loadData').removeClass("dropload-noData").addClass("dropload-hasData").html("点击加载更多数据...");
			isLoadNewStudent = false;
			isLoadMiddleStudent = false;
			isLoadInternatStudent = false;
			xsPage = 1;
			cbPage = 1;
			gjPage = 1;
			if(id == 'newStudentTab') {
				xsPage += 1;
				isLoadNewStudent = true;
				getData(1, "newStudent");
			}else if(id == 'middleStudentTab') {
				cbPage += 1;
				isLoadMiddleStudent = true;
				getData(1, "middleStudent");
			}else if(id == 'internatStudentTab') {
				gjPage += 1;
				isLoadInternatStudent = true;
				getData(1, "internatStudentTab");
			}
		})
		//初始化新生数据
		isLoadNewStudent = true;
		xsPage += 1;
		getData(1, "newStudent");
		$('#newStudentTab').on('click', function() {
			if(!isLoadNewStudent) {
				isLoadNewStudent = true;
				xsPage += 1;
				getData(1, "newStudent");
			}
		});
		$('#middleStudentTab').on('click', function() {
			if(!isLoadMiddleStudent) {
				isLoadMiddleStudent = true;
				cbPage += 1;
				getData(1, "middleStudent");
			}
		});
		$('#internatStudentTab').on('click', function() {
			if(!isLoadInternatStudent) {
				isLoadInternatStudent = true;
				gjPage += 1;
				getData(1, "internatStudent");
			}
		});
		$(".dropload-down").on("click", ".dropload-hasData", function() {
			var id = $(this).closest(".weui_tab_bd_item").find(".weui_cells").attr("id");
			var cpage;
			if(id == 'newStudent') {
				cpage = xsPage;
				xsPage += 1;
			}else if(id == 'middleStudent') {
				cpage = cbPage;
				cbPage += 1;
			}else if(id == 'internatStudent') {
				cpage = gjPage;
				gjPage += 1;
			}
			getData(cpage, id);
		});
	});
	
	//从服务器获取json ,status 首次页面加载1，追加数据 2 
	function getData(page, signUpType){
		var rows = 5;
		$.ajax({
			type: "post",
			url: basePath + "/ls/signUp/student/page/query",
			data: {
				"page": page,
				"rows": rows,
				"signUpType": signUpType,
				startDate: $("#startDate").val(),
				endDate: $("#endDate").val()
			},
			dataType:"json",
			success:function(data){
				if(data.code == '000') {
					var temp = data.data.rows;
					if(temp.length == 0 || page*rows >= data.data.total) {// 如果没有数据
						$("#" + signUpType).closest(".weui_tab_bd_item").find('.loadData').removeClass("dropload-hasData").addClass("dropload-noData").html("没有更多数据了");
	                }
				    addData(data.data.rows, signUpType);
				}
			     
			}
		});
	}
	//添加新生的数据,page 页数，rows 每页记录数 ，
	//signUpType 报名类型 ，和id相同  ， 新生  newStudent，插班生 middleStudent ,国际生 internatStudent
	function addData(data, id) {
		var id = "#" + id;
		var html = "";
		for (var i = 0; i < data.length; i++) {
			html += '<a class="weui_cell" href="<%=basePath%>/ls/signUp/student/detail?id='+data[i].id+'">\
            <div class="weui_cell_bd weui_cell_primary">\
				<h4 class="weui_media_title f-blue" style="white-space: inherit;">'+data[i].studentName+'</h4>\
				<p class="weui_media_desc mt5">应聘时间：'+getTime(data[i].signUpTime,"yyyy-MM-dd hh:mm")+'</p>\
   			   </div>\
   			   <span class="weui_cell_ft"></span>\
			</a>';
		}
		$(id).append(html);
	};
</script>
</html>